package my.jwds.p88;

import java.util.Arrays;

public class Merge {

    public static void main(String[] args) {
        Merge o = new Merge();
        int [] nums1 = {1,2,3,0,0,0};
        int [] nums2 = {4,5,6};
        o.merge(nums1,3,nums2,nums2.length);
        System.out.println(Arrays.toString(nums1));
    }


    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int length = m+n,index = length-1;
        m--;
        n--;
        while(m >=-1 && n>=0){
            if (m == -1){
                nums1[index] = nums2[n--];
            } else if (nums1[m] < nums2[n]){
                nums1[index] = nums2[n--];
            }else{
                nums1[index] = nums1[m--];
            }
            index--;
        }
    }

}
